<?php

class Education extends Frank implements iFrank {

    //properties
    protected $description;
    protected $yearIn;
    protected $yearOut;
    protected $place;
    protected $diploma;
    protected $website;
    protected $image;
    protected $longDescription;
    protected $extra;

    //Getters
    public function description() {
        return $this->description;
    }
    
    public function yearIn() {
        return $this->yearIn;
    }

    public function yearOut() {
        return $this->yearOut;
    }

    public function place() {
        return $this->place;
    }

    public function diploma() {
        return $this->diploma;
    }

    public function website() {
        return $this->website;
    }

    public function image() {
        return $this->image;
    }

    public function extra() {
        return $this->extra;
    }
    
    public function longDescription() {
        return $this->longDescription;
    }

    public function __construct($id, $name, $description, $yearIn, $yearOut, $place, $diploma, $website, $image, $longDescription, $extra) {
        $this->id = $id;
        $this->name = $name;
        $this->description = $description;
        $this->yearIn = $yearIn;
        $this->yearOut = $yearOut;
        $this->place = $place;
        $this->diploma = $diploma;
        $this->website = $website;
        $this->image = $image;
        $this->longDescription = $longDescription;
        $this->extra = $extra;
    }

    public static function getObject($row) {
        return new Education($row["id"], $row["name"], $row["description"], $row["year_in"], $row["year_out"], $row["place"], $row["diploma"], $row["website"], $row["image_name"], $row["long_description"], $row["extra_info"]);
    }

    public static function getAll($toArray = false, $fields = null, $query = null, $db = null) {
        $query = "select * from `" . EDUCATION_TABLE . "` order by year_in desc";
        return parent::getAll($toArray, $fields, $query, $db);
    }
    
    public static function getById($id, $toArray = false, $fields = null, $query = null, $db = null){
        $query = 'select * from `' . EDUCATION_TABLE . '` where id = '.$id;
        return parent::getById($id, $toArray, $fields, $query, $db);
    }

    /*protected function toArray($propertyArray = null) {
        return parent::toArray(array('description', 'name'));
    }*/

    public static function getAllForSkillId($skillId, $db, $toArray = false) {
        $query = 'select * '
                . 'from  `' . EDUCATION_TABLE . '` '
                . 'join `' . SKILL_EDUCATION_TABLE . '` ON `' . EDUCATION_TABLE . '`.id = `' . SKILL_EDUCATION_TABLE . '`.education_id '
                . 'where `' . SKILL_EDUCATION_TABLE . '`.skill_id = ' . $skillId;
        return parent::getAll($toArray, null, $query, $db);
    }

}

?>